package com.inmaytide.website.utils.pagination;

import com.inmaytide.website.utils.configurations.SystemConstants;
import org.apache.ibatis.session.RowBounds;

import java.io.Serializable;
import java.util.List;

/**
 * 分页查询相关信息
 *
 * @author Moss
 * @version 1.0.0
 * @since May 22, 2016
 */
public class Pagination<T extends Serializable> implements Serializable {

    private static final long serialVersionUID = 9148954300226899218L;

    private Integer pageNumber = SystemConstants.DEFAULT_PAGE_NUMBER;
    private Integer pageSize = SystemConstants.DEFAULT_PAGE_SIZE;
    private Integer count = 0;
    private Object conditions;
    private List<T> result;

    public Pagination() {

    }

    public Pagination(Integer pageSize, Integer pageNumber) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
    }

    public Integer getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(Integer pageNumber) {
        this.pageNumber = pageNumber;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getBiggestPageNumber() {
        int tmp = count % pageSize;
        return tmp > 0 ? (count / pageSize) + 1 : (count / pageSize);
    }

    public Object getConditions() {
        return conditions;
    }

    public void setConditions(Object conditions) {
        this.conditions = conditions;
    }

    public RowBounds getRowBounds() {
        return new RowBounds(getOffset(), getLimit());
    }

    public int getOffset() {
        return (pageNumber - 1) * pageSize;
    }

    public int getLimit() {
        return pageSize;
    }

    /**
     * @return the result
     */
    public List<T> getResult() {
        return result;
    }

    /**
     * @param result the result to set
     */
    public void setResult(List<T> result) {
        this.result = result;
    }
}
